using System;
using System.Text;
using System.Data;
using System.Collections;

using WP.MF.DataEntity;
using WP.MF.DataAccess;
using WP.MF.BusinessRule;
using WP.DB;
using WP.Commons;

namespace WP.MF.BusinessLogical
{
    public class MPrinterBLL: IBusinessLogical     
    {
        ArrayList MultiList=new ArrayList();
        MPrinterDAL mPrinterDAL = new MPrinterDAL();
        public MPrinterBLL()
		{
        }
        #region ***For implement interface
        #region Select Record by RECID
        public IDataEntity SelectDataByRecID(string strRecID)
        {
            DBAccess dBAccess = new DBAccess(false, false);
            try
            {
                MPrinterDEL mPrinterDEL = mPrinterDAL.SelectDataByRecID(dBAccess, strRecID);
                return mPrinterDEL as IDataEntity;
            }
            catch (Exception e)
            {
                ExceptionManager.ProcessException(e);
                return null;
            }
            finally
            {
                dBAccess.CloseCon();
            }
        }
        #endregion
        #region Insert MPrinter
        public bool Insert(DBAccess dBAccess, MPrinterDEL mPrinterDEL)
        {
            bool bFlag = true;
            MPrinterBRL mPrinterBRL = new MPrinterBRL();
            BaseFunctions.SpecialCharDeal(mPrinterDEL);
            if (mPrinterBRL.InsertValid(dBAccess, mPrinterDEL))
            {
                mPrinterDAL.InsertMPrinter(dBAccess, mPrinterDEL);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;
        }
        public bool Insert(IDataEntity iMPrinterDEL)
        {
            bool bReturn = true;
            DBAccess dBAccess = null;
            MPrinterDEL mPrinterDEL = iMPrinterDEL as MPrinterDEL;
            dBAccess = new DBAccess(false, true);
            try
            {
                bReturn = Insert(dBAccess, mPrinterDEL);
                if (bReturn)
                {
                    dBAccess.CommitTranAndCloseCon();
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTran();
                bReturn = false;
                ExceptionManager.ProcessException(e);
            }
            return bReturn;
        }
        #endregion
        #region Update MPrinter
        public bool Update(DBAccess dBAccess, MPrinterDEL mPrinterDEL)
        {
            bool bFlag = true;
            MPrinterBRL mPrinterBRL = new MPrinterBRL();
            BaseFunctions.SpecialCharDeal(mPrinterDEL);
            if (mPrinterBRL.UpdateValid(dBAccess, mPrinterDEL))
            {
                mPrinterDAL.UpdateMPrinter(dBAccess, mPrinterDEL);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;
        }
        public bool Update(IDataEntity iMPrinterDEL)
        {
            bool bReturn = true;
            MPrinterDEL mPrinterDEL = iMPrinterDEL as MPrinterDEL;
            DBAccess dBAccess = new DBAccess(false, true);
            try
            {
                bReturn = Update(dBAccess, mPrinterDEL);
                if (bReturn)
                {
                    dBAccess.CommitTranAndCloseCon();
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTran();
                ExceptionManager.ProcessException(e);
                bReturn = false;
            }
            return bReturn;
        }
        #endregion
        #region Delete MPrinter
        public bool Delete(string strRecId, byte[] btOldRecStamp)
        {
            MPrinterBRL mPrinterBRL = new MPrinterBRL();
            DBAccess dBAccess = new DBAccess(false, true);
            try
            {
                if (mPrinterBRL.DeleteValid(dBAccess, strRecId, btOldRecStamp))
                {
                    mPrinterDAL.DeleteMPrinter(dBAccess, int.Parse(strRecId));
                    dBAccess.CommitTranAndCloseCon();
                    return true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                    return false;
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                return false;
            }
        }
        #endregion
        #endregion***
        #region Select MPrinter
        public MPrinterDEL SelectMPrinterByKey(int RecID)
        {
            MPrinterDEL mPrinterDEL = new MPrinterDEL();
            DBAccess dBAccess = new DBAccess();
            return mPrinterDAL.SelectMPrinterByKey(dBAccess, RecID);
        }
        #endregion
    }
}
